Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Constant type/value properties #280

Merged
merged 24 commits into from
Oct 9, 2023

Conversation

eugenesvk
Copy link
Contributor

@eugenesvk eugenesvk commented Oct 6, 2023

This is some draft of the edits I've made (currently only to v26 as that's the version of the locally generated docs) to be able to extract a list of constants from a crate as mentioned in #279

Unresolved question:

  • currently I'm using serde json to de/ser the Type since there is no conversion to trustfall::FieldValue implemented for this type, but that seems clunky, so what's the easiest way to have a proper support of this conversion (is it only possible in the trustfall main crate?)
    • it's clunky since on the receiving side I can only try_into_struct
  struct Output {
    // type_  	: rustdoc_types::Type, // Type→FieldValue not implemented, use ↓ json→string
    type_     	: String,
  }
let results:Vec<_> = trustfall::execute_query(&schema, adapter.clone(), query, variables.clone()).expect("failed to run query")
    .map(|row| row.try_into_struct::<Output>().expect("shape mismatch")).collect();

into a string field, can't make it deserialise from json automatically).

(haven't done any formatting/tests yet)

allow reading constant value/expr/is_literal and type (this one serialized to a json string since there is no impl to convert it to FieldValue)
@eugenesvk eugenesvk marked this pull request as draft October 6, 2023 10:47
Copy link
Owner

@obi1kenobi obi1kenobi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely done! Thanks for the PR, I'd be happy to merge something like this.

I have a few suggestions around how to get the type info out more conveniently, and around some of the docs structure. Nothing major, should be resolvable in just a couple of minutes.

Also, are you interested in associated constants as well, or just regular ones? If the associated constants are missing fields, I'd be happy to take a PR there as well.

src/rustdoc_schema.graphql Outdated Show resolved Hide resolved
src/rustdoc_schema.graphql Outdated Show resolved Hide resolved
src/rustdoc_schema.graphql Outdated Show resolved Hide resolved
eugenesvk and others added 3 commits October 7, 2023 00:26
Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>
@eugenesvk
Copy link
Contributor Author

eugenesvk commented Oct 6, 2023

Also, are you interested in associated constants as well, or just regular ones? If the associated constants are missing fields, I'd be happy to take a PR there as wel

just the regular ones, the associated ones already have the default value though seems to miss the type_ field, so added that as well

AssocConst
Fields
type_: Type
default: Option<String>

src/rustdoc_schema.graphql Outdated Show resolved Hide resolved
src/rustdoc_schema.graphql Outdated Show resolved Hide resolved
src/rustdoc_schema.graphql Outdated Show resolved Hide resolved
Copy link
Owner

@obi1kenobi obi1kenobi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of nitpicks on docs and such, otherwise it's good to merge. I usually don't merge PRs marked "draft" so when you've had a chance to take one more look and feel it's good to merge on your end, move it out of the draft state and I'll give it another quick look as well and then merge + publish.

Comment on lines +712 to +713
If the constant is set:

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor formatting nit:

Suggested change
If the constant is set:
If the constant is set:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually intentional since no space after the "header" breaks the formatting, so instead of 2 bullet points you get one line (at least in my Sublime editor with LSP plugin)

Not sure how it works in your wasm playground or any other tools

Let me know if you want to add an extra empty line before anyway (personally prefer a bit more compact, but up to you)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah nice, thanks for double-checking it in the editor.

Let's add the extra empty line before the block, though. I think that way it's a bit more readable when it's not rendered as markdown.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just the adding the newline, so I'll merge this as-is and add the newline in a separate PR and then cut a release so we can move faster.

src/rustdoc_schema.graphql Show resolved Hide resolved
Comment on lines -885 to -888
trait BatchIterator<const MIN: usize> {
const SIZE: usize = 16; // `"16"` is the default
const LOG_AS: &'static str = "batch"; // `"\"batch\""` is the default, including escaped quotes
const MIN_SIZE: usize = MIN; // "MIN" is the default, referring to the other constant's name
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the original example, MIN_SIZE was referring to the const generic constant. In the new example it refers to a local sibling constant only, and there's no example with a const generic. Mind adding a const generic example as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

restored MIN to be the const generic and the sibling is just a standalone NUM number

src/rustdoc_schema.graphql Outdated Show resolved Hide resolved
src/rustdoc_schema.graphql Outdated Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
src/adapter/properties.rs Outdated Show resolved Hide resolved
eugenesvk and others added 5 commits October 9, 2023 03:25
Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>
Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>
Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>
Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>
@eugenesvk eugenesvk marked this pull request as ready for review October 8, 2023 21:20
@eugenesvk
Copy link
Contributor Author

Done the last thing I wanted - updated a test, though had to split logic for Constants with more properties like expr/value and for GlobalValues that don't have those and only test name/path as before

(although I've only run the local test for this updaed const crate, not the whole test suite)

Then pending the unresolved doc formatting edits should be more or less fine?

And as far as I understood, porting to other rustdocs versions is semi-auto-done with the help of your magic script?

@obi1kenobi
Copy link
Owner

Looks great. Going to merge this, add the newline in the docs, and cut a new release that you should be able to use.

Thanks for the help! Let me know how this all works out in your use case.

And as far as I understood, porting to other rustdocs versions is semi-auto-done with the help of your magic script?

Yup! I'll take care of porting it and cut a release for all the rustdoc versions that cargo-semver-checks currently supports: v24, v26, v27.

@obi1kenobi obi1kenobi enabled auto-merge (squash) October 9, 2023 03:35
@obi1kenobi obi1kenobi merged commit 85a4470 into obi1kenobi:rustdoc-v26 Oct 9, 2023
8 checks passed
obi1kenobi added a commit that referenced this pull request Oct 9, 2023
* add Constant property resolution function

allow reading constant value/expr/is_literal and type (this one serialized to a json string since there is no impl to convert it to FieldValue)

* add Constant property rustdocs example

* add Constant property rustdoc schema

* dep: add serde_json for Constant property Type

* fix clippy

* uglify with rustfmt

* Update src/rustdoc_schema.graphql

Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>

* squeeze doc comment

* add a doc comment note referencing a more comprehensive example

to avoid repeating said example

* add type_ field to AssociatedConstant property resolution function

(temporary in the json string format)

* add type_ field to AssociatedConstant property rustdoc schema

* split schema docs so that each Constant property is documented

* update schema doc comment

* update schema docs trait name

* fix a typo in schema docs

* remove type Assoc/Const property

until trustfall adds proper support for custom scalar types

* remove type Assoc/Const property from schema

* fix a typo in schema docs

Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>

* dep: remove serde_json since Constant property Type was removed

Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>

* remove unstable rustdocs example for Constant properties

Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>

* Update formatting of the schema docs

Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>

* Update AssociatedConstant example to refer to a const generic

* Update Constant test with extra properties

expr/value/is_literal

---------

Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>
obi1kenobi added a commit that referenced this pull request Oct 9, 2023
* add Constant property resolution function

allow reading constant value/expr/is_literal and type (this one serialized to a json string since there is no impl to convert it to FieldValue)

* add Constant property rustdocs example

* add Constant property rustdoc schema

* dep: add serde_json for Constant property Type

* fix clippy

* uglify with rustfmt

* Update src/rustdoc_schema.graphql

Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>

* squeeze doc comment

* add a doc comment note referencing a more comprehensive example

to avoid repeating said example

* add type_ field to AssociatedConstant property resolution function

(temporary in the json string format)

* add type_ field to AssociatedConstant property rustdoc schema

* split schema docs so that each Constant property is documented

* update schema doc comment

* update schema docs trait name

* fix a typo in schema docs

* remove type Assoc/Const property

until trustfall adds proper support for custom scalar types

* remove type Assoc/Const property from schema

* fix a typo in schema docs

Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>

* dep: remove serde_json since Constant property Type was removed

Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>

* remove unstable rustdocs example for Constant properties

Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>

* Update formatting of the schema docs

Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>

* Update AssociatedConstant example to refer to a const generic

* Update Constant test with extra properties

expr/value/is_literal

---------

Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>
obi1kenobi added a commit that referenced this pull request Oct 9, 2023
* add Constant property resolution function

allow reading constant value/expr/is_literal and type (this one serialized to a json string since there is no impl to convert it to FieldValue)

* add Constant property rustdocs example

* add Constant property rustdoc schema

* dep: add serde_json for Constant property Type

* fix clippy

* uglify with rustfmt

* Update src/rustdoc_schema.graphql



* squeeze doc comment

* add a doc comment note referencing a more comprehensive example

to avoid repeating said example

* add type_ field to AssociatedConstant property resolution function

(temporary in the json string format)

* add type_ field to AssociatedConstant property rustdoc schema

* split schema docs so that each Constant property is documented

* update schema doc comment

* update schema docs trait name

* fix a typo in schema docs

* remove type Assoc/Const property

until trustfall adds proper support for custom scalar types

* remove type Assoc/Const property from schema

* fix a typo in schema docs



* dep: remove serde_json since Constant property Type was removed



* remove unstable rustdocs example for Constant properties



* Update formatting of the schema docs



* Update AssociatedConstant example to refer to a const generic

* Update Constant test with extra properties

expr/value/is_literal

---------

Co-authored-by: Evgeny <eugenesvk@users.noreply.github.com>
obi1kenobi added a commit that referenced this pull request Oct 9, 2023
* add Constant property resolution function

allow reading constant value/expr/is_literal and type (this one serialized to a json string since there is no impl to convert it to FieldValue)

* add Constant property rustdocs example

* add Constant property rustdoc schema

* dep: add serde_json for Constant property Type

* fix clippy

* uglify with rustfmt

* Update src/rustdoc_schema.graphql



* squeeze doc comment

* add a doc comment note referencing a more comprehensive example

to avoid repeating said example

* add type_ field to AssociatedConstant property resolution function

(temporary in the json string format)

* add type_ field to AssociatedConstant property rustdoc schema

* split schema docs so that each Constant property is documented

* update schema doc comment

* update schema docs trait name

* fix a typo in schema docs

* remove type Assoc/Const property

until trustfall adds proper support for custom scalar types

* remove type Assoc/Const property from schema

* fix a typo in schema docs



* dep: remove serde_json since Constant property Type was removed



* remove unstable rustdocs example for Constant properties



* Update formatting of the schema docs



* Update AssociatedConstant example to refer to a const generic

* Update Constant test with extra properties

expr/value/is_literal

---------

Co-authored-by: Evgeny <eugenesvk@users.noreply.github.com>
@obi1kenobi
Copy link
Owner

New versions are available on crates.io!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants